<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_caidan extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('Caidan_mdl');
	}

	public function index()
	{
		$this->caidan_list();
	}

	public function caidan_list()
	{
		$keywords = $this->input->post('keywords');
		$page = max(1, intval($this->input->post('pageNum')));
		$limit = 18; //每页显示数
		$offset = ($page - 1) * $limit;


		//分页
		$data['totalCount'] = 40000;
		$data['numPerPage'] = $limit;
		$data['currentPage'] = $page;
		$data['keywords'] = $keywords;
		if ($keywords)
		{
			$data['caidan_list'] = $this->Caidan_mdl->get_caidan_search($keywords, $offset, $limit)->result_array();
		}
		else
		{
			$data['caidan_list'] = $this->Caidan_mdl->get_caidan_list($offset, $limit)->result_array();
		}
		$this->load->view('caidan', $data);
	}

	public function caidan_edit($id = '')
	{
		if(empty($id) || !is_numeric($id))
		{
			show_error('失败：参数有误');
			exit();
		}

		if ($this->input->post('submit') == 'ok')
		{
			$arr = array(
				'title' => $this->input->post('title'),
				'desc' => $this->input->post('desc'),
				'image' => $this->input->post('image_fileName'),
				'status' => $this->input->post('status'),
				'views' => $this->input->post('views'),
				'uptime' => strtotime($this->input->post('uptime'))
			);
			$result = $this->Caidan_mdl->caidan_update($arr, $id);
			$this->_jui_message('操作成功');
		}
		else
		{
			$data['caidan_info'] = $this->Caidan_mdl->get_caidan_by_id($id);

			/** 不存在? */
			if(!$data['caidan_info'])
			{
				redirect('shicai/category');
				exit();
			}
			$this->load->view('caidan_edit', $data);
		}

	}
	
	public function caidan_del($id = '')
	{
		$result = $this->Caidan_mdl->caidan_delete($id);
		$this->_jui_message('操作成功');
	}
}

/* End of file caipu.php */
/* Location: ./application/controllers/manage/caipu.php */